#include "WinUnit.h"
#include "CcpfHandInfoBuilder.h"
#include "Hand.h"
#include "PlayerHandInfo.h"
#include <list>

using namespace std;

namespace
{
	CcpfHandInfoBuilder builder;
	Hand h;	
}

bool VerifyCcpfOp(const PlayerHandInfo &playerHandInfo, bool ccpf, bool ccpfOp);

BEGIN_TEST(CanGetCcpfOpTest)
{		
	list<Action> actions;
	actions.push_back(Action("player1", POST, 1));
	actions.push_back(Action("player2", POST, 2));
	actions.push_back(Action("player3", RAISE, 4));
	actions.push_back(Action("player4", FOLD, 0));
	h.Actions(actions);
	
	list<Player> players;
	players.push_back(Player("player1", 1, 100, false, true, false));
	players.push_back(Player("player2", 2, 100, true, false, false));
	players.push_back(Player("player3", 3, 100, false, false, false));
	players.push_back(Player("player4", 4, 100, false, false, true));
	h.Players(players);

	HandInfo handInfo(h);
	builder.Fill(handInfo, h);

	WIN_ASSERT_TRUE(
		VerifyCcpfOp(handInfo.PlayerInfo("player1"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player2"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player3"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player4"), 0, 1)
	);
}
END_TEST

BEGIN_TEST(CanGetCcpfTest)
{		
	list<Action> actions;
	actions.push_back(Action("player1", POST, 1));
	actions.push_back(Action("player2", POST, 2));
	actions.push_back(Action("player3", RAISE, 4));
	actions.push_back(Action("player4", CALL, 6));
	h.Actions(actions);
	
	list<Player> players;
	players.push_back(Player("player1", 1, 100, false, true, false));
	players.push_back(Player("player2", 2, 100, true, false, false));
	players.push_back(Player("player3", 3, 100, false, false, false));
	players.push_back(Player("player4", 4, 100, false, false, true));
	h.Players(players);

	HandInfo handInfo(h);
	builder.Fill(handInfo, h);

	WIN_ASSERT_TRUE(
		VerifyCcpfOp(handInfo.PlayerInfo("player1"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player2"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player3"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player4"), 1, 1)
	);
}
END_TEST

BEGIN_TEST(CanIgnoreBlindsCcpfTest)
{		
	list<Action> actions;
	actions.push_back(Action("player1", POST, 1));
	actions.push_back(Action("player2", POST, 2));
	actions.push_back(Action("player3", RAISE, 4));
	actions.push_back(Action("player4", FOLD, 0));
	actions.push_back(Action("player1", CALL, 5));
	actions.push_back(Action("player2", CALL, 4));
	
	h.Actions(actions);
	
	list<Player> players;
	players.push_back(Player("player1", 1, 100, false, true, false));
	players.push_back(Player("player2", 2, 100, true, false, false));
	players.push_back(Player("player3", 3, 100, false, false, false));
	players.push_back(Player("player4", 4, 100, false, false, true));
	h.Players(players);

	HandInfo handInfo(h);
	builder.Fill(handInfo, h);

	WIN_ASSERT_TRUE(
		VerifyCcpfOp(handInfo.PlayerInfo("player1"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player2"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player3"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player4"), 0, 1)
	);
}
END_TEST

BEGIN_TEST(HeadsUpCcpfTest)
{		
	list<Action> actions;
	actions.push_back(Action("player1", POST, 1));
	actions.push_back(Action("player2", POST, 2));
	actions.push_back(Action("player1", RAISE, 5));
	actions.push_back(Action("player2", CALL, 4));
	
	h.Actions(actions);
	
	list<Player> players;
	players.push_back(Player("player1", 1, 100, false, true, false));
	players.push_back(Player("player2", 2, 100, true, false, false));
	h.Players(players);

	HandInfo handInfo(h);
	builder.Fill(handInfo, h);

	WIN_ASSERT_TRUE(
		VerifyCcpfOp(handInfo.PlayerInfo("player1"), 0, 0)
		&& VerifyCcpfOp(handInfo.PlayerInfo("player2"), 0, 0)
	);
}
END_TEST

bool VerifyCcpfOp(const PlayerHandInfo &playerHandInfo, bool ccpf, bool ccpfOp)
{
	return (playerHandInfo.Ccpf() == ccpf && playerHandInfo.CcpfOp() == ccpfOp);
}